package cn.mickey.exchange.api;


import cn.mickey.exchange.annotation.LoginUser;
import cn.mickey.exchange.annotation.RedisCache;
import cn.mickey.exchange.domain.JsonResponse;
import cn.mickey.exchange.domain.model.OrderAddressModel;
import cn.mickey.exchange.domain.model.UserModel;
import cn.mickey.exchange.service.OrderAddressService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RedisCache
@RestController
@RequestMapping("/order-address")
public class OrderAddressApi {

    @Resource
    private OrderAddressService orderAddressService;

    @PostMapping("/add")
    public JsonResponse addOrderAddress(@LoginUser UserModel user,
                                        @RequestBody OrderAddressModel orderAddressModel){
        return JsonResponse.success(orderAddressService.addOrderAddress(orderAddressModel));
    }


    @PostMapping("/update")
    public JsonResponse updateOrderAddress(@RequestBody OrderAddressModel orderAddressModel){
        if(orderAddressService.updateOrderAddress(orderAddressModel)){
            return JsonResponse.success(orderAddressModel);
        }
        return JsonResponse.fail("系统错误!");
    }

    @GetMapping("/info")
    public JsonResponse getOrderAddress(@RequestParam Long orderId){
        return JsonResponse.success(orderAddressService.getOrderAddress(orderId));
    }
}
